package com.qqtop10.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.qqtop10.manager.model.Result;
import com.qqtop10.manager.model.SystemInfo;
import com.qqtop10.manager.service.SystemInfoService;

@Controller
@RequestMapping("/manager/system/info")
public class SystemInfoController extends BaseController {
	@Autowired
	private SystemInfoService systemInfoService;

	@RequestMapping("update.do")
	@ResponseBody
	public Result update() {
		SystemInfo input = new SystemInfo();
		fill(input);
		MultipartFile logo = getFile("logo");
		if (logo != null && !logo.isEmpty()) {
			input.setLogo(save(logo));
		}
		if (input == null || input.getCellphone() == null ||  input.getContacts() == null
				|| input.getCopyright() == null || 
						/*input.getCity() == null 	|| input.getProvince() == null 
								|| input.getDistrict() == null||*/
				 input.getDetailed_address() == null
				 || input.getDomain_name() == null || input.getIcp() == null
				|| input.getKeywords() == null || input.getLogo() == null || input.getName() == null
			
						||input.getDescription() == null 
				|| input.getTelephone() == null || input.getUrl() == null) {
			return err("有些必须的参数未指定。");
		}
		try {
			if (systemInfoService.update(input)) {
				return html("操作成功!", input);
			}
			return err("操作失败!");
		} catch (Exception e) {
			return excep(e);
		}
	}

	@RequestMapping("get.do")
	@ResponseBody
	public Result get(SystemInfo input) {
		try {
			return ok(systemInfoService.get(input));
		} catch (Exception e) {
			return excep(e);
		}
	}
}
